<?php

class Register_m extends CI_Model {
   
   /**
    * Validate the login's data with the database
    * @param string $user_name
    * @param string $password
    * @return void
    */
   function validate($user_name, $password) {
      $this->db->where('user_name', $user_name);
      $this->db->where('pass_word', $password);
      $query = $this->db->get('membership');
      
      if ($query->num_rows == 1) {
         return true;
      }
   }
   
	function check_email($email){
		$this->db->where('email', $email);
      $query = $this->db->get('users');
      return 
		$query->num_rows;
		echo $this->db->last_query();die;
	}
   
   /**
    * Store the new user's data into the database
    * @return boolean - check the insert
    */
   function update_user($data) {      
      if($data['id']){
			$this->db->where('id', $data['id']);
			return $this->db->update('users', $data);
		}else{
			return $this->db->insert('users', $data);
		}
   } //create_member
	
	function get_tinh_thanh($id = ''){
		if($id)
			$this->db->where('id', $id);
		$this->db->where('trang_thai', 1);
		$result = $this->db->get('tinh_thanh')->result();
		$data = array();		
		foreach($result as $obj)
			$data[$obj->id]	= $obj->ten;
		return $data;
	}
	
	function get_quan_huyen($tinh_thanh_id = '', $is_array = false){		
		$this->db->where('tinh_id', $tinh_thanh_id);
		$result = $this->db->get('quan_huyen')->result();
		if(!$is_array)
			return $result;
		$data = array();
		foreach($result as $obj)
			$data[$obj->id]	= $obj->ten;
		return $data;
	}
}
